/*
 * Created on Mar 21, 2010
 */
package ro.letsdoitromania.forms;

import javax.microedition.lcdui.*;
import com.mgmaps.app.APPCommands;
import com.mgmaps.tools.UITools;
import com.mgmaps.utils.LS;
import ro.letsdoitromania.LDIRMidlet;
import ro.letsdoitromania.TrashPointData;

public class ViewForm implements CommandListener {
  private Form form;
  
  private static ViewForm instance;
  private Displayable parent;
  
  private TrashPointData tpd;
  
  public static ViewForm getInstance() {
    if (instance == null)
      instance = new ViewForm();
    return instance;
  }
  
  private ViewForm() {
  }
  
  public void show(TrashPointData p, String title, Command[] commands, CommandListener listener) {
    tpd = p;
    
    form = UITools.buildForm(form, title, tpd.buildItems(), commands, listener); 
    
    Display.getDisplay(LDIRMidlet.instance).setCurrent(form);    
  }
  
  public void show(TrashPointData p, Displayable par) {
    show(p, par, new Command[] { APPCommands.instance.backCommand });
  }
  
  public void show(TrashPointData p, Displayable par, Command[] commands) {
    parent = par;
    show(p, LS.get("ldir.view.title"), commands, this);
  }

  public void commandAction(Command cmd, Displayable disp) {
    if (cmd == APPCommands.instance.backCommand)
      Display.getDisplay(LDIRMidlet.instance).setCurrent(parent);
    else if (cmd == APPCommands.instance.editCommand)
      AddEditForm.getInstance().showEdit(tpd);
    else if (cmd == APPCommands.instance.deleteCommand) {
      DeleteConfirmForm.getInstance().show(tpd);
    }
  }
}
